package com.cqut.forum.entity;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Lob;

import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * @author yangxun
 * Article entity
 */
@Entity
@Table(name = "article", catalog = "forum")
public class Article implements java.io.Serializable {

	// Fields

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Integer articleId;
	private String articleName;
	private ArticleGroup articleGroup;
	private Integer visitTimes;
	private Date publishTime;
	private Boolean articleState;
	private String articleContents;
	private Integer reviewTimes;
	private Integer moduleId;
	private Boolean isReview;
	private Boolean isPublic;
	private String articleKeyWords;
	private Date lastReplyTime;
	private Integer ownerId;
	private Set<ArticleReply> articleReplies = new HashSet<ArticleReply>(0);
	//private Set<AritcleVisitLog> aritcleVisitLogs = new HashSet<AritcleVisitLog>(
	//		0);

	// Constructors

	/** default constructor */
	public Article() {
	}

	/** full constructor */
	public Article(ArticleGroup articleGroup, Integer visitTimes,String articleName,
			Date publishTime, Boolean articleState, String articleContents,
			Integer reviewTimes, Integer moduleId, Boolean isReview,Boolean isPublic,
			Integer ownerId,
			String articleKeyWords, Date lastReplyTime, Set<ArticleReply> articleReplies
			/*Set<AritcleVisitLog> aritcleVisitLogs*/) {
		this.articleGroup = articleGroup;
		this.articleName = articleName;
		this.visitTimes = visitTimes;
		this.publishTime = publishTime;
		this.articleState = articleState;
		this.articleContents = articleContents;
		this.reviewTimes = reviewTimes;
		this.moduleId = moduleId;
		this.isReview = isReview;
		this.isPublic = isPublic;
		this.ownerId = ownerId;
		this.articleKeyWords = articleKeyWords;
		this.lastReplyTime = lastReplyTime;
		this.articleReplies = articleReplies;
		//this.aritcleVisitLogs = aritcleVisitLogs;
	}

	// Property accessors
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "article_id", unique = true, nullable = false)
	public Integer getArticleId() {
		return this.articleId;
	}

	public void setArticleId(Integer articleId) {
		this.articleId = articleId;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "article_group_id")
	public ArticleGroup getArticleGroup() {
		return this.articleGroup;
	}

	public void setArticleGroup(ArticleGroup articleGroup) {
		this.articleGroup = articleGroup;
	}

	@Column(name = "visit_times")
	public Integer getVisitTimes() {
		return this.visitTimes;
	}

	public void setVisitTimes(Integer visitTimes) {
		this.visitTimes = visitTimes;
	}

	@Column(name = "publish_time", length = 10)
	public Date getPublishTime() {
		return this.publishTime;
	}

	public void setPublishTime(Date publishTime) {
		this.publishTime = publishTime;
	}

	@Column(name = "article_state")
	public Boolean getArticleState() {
		return this.articleState;
	}

	public void setArticleState(Boolean articleState) {
		this.articleState = articleState;
	}
	
	@Column(name = "article_name", length = 100)
	public String getArticleName() {
		return articleName;
	}

	public void setArticleName(String articleName) {
		this.articleName = articleName;
	}
	
	@Lob
	@Column(name = "article_contents",columnDefinition="TEXT")
	//@Column(name = "article_contents", length = 1000)
	public String getArticleContents() {
		return this.articleContents;
	}

	public void setArticleContents(String articleContents) {
		this.articleContents = articleContents;
	}

	@Column(name = "review_times")
	public Integer getReviewTimes() {
		return this.reviewTimes;
	}

	public void setReviewTimes(Integer reviewTimes) {
		this.reviewTimes = reviewTimes;
	}

	@Column(name = "module_id")
	public Integer getModuleId() {
		return this.moduleId;
	}

	public void setModuleId(Integer moduleId) {
		this.moduleId = moduleId;
	}

	@Column(name = "is_review")
	public Boolean getIsReview() {
		return this.isReview;
	}

	public void setIsReview(Boolean isReview) {
		this.isReview = isReview;
	}

	@Column(name = "is_public")
	public Boolean getIsPublic() {
		return isPublic;
	}

	public void setIsPublic(Boolean isPublic) {
		this.isPublic = isPublic;
	}

	@Column(name = "article_key_words", length = 100)
	public String getArticleKeyWords() {
		return this.articleKeyWords;
	}

	public void setArticleKeyWords(String articleKeyWords) {
		this.articleKeyWords = articleKeyWords;
	}
	@Column(name = "owner_id")
	public Integer getOwnerId() {
		return ownerId;
	}

	public void setOwnerId(Integer ownerId) {
		this.ownerId = ownerId;
	}

	@Column(name = "last_reply_time")
	public Date getLastReplyTime() {
		return lastReplyTime;
	}

	public void setLastReplyTime(Date lastReplyTime) {
		this.lastReplyTime = lastReplyTime;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "article")
	public Set<ArticleReply> getArticleReplies() {
		return this.articleReplies;
	}

	public void setArticleReplies(Set<ArticleReply> articleReplies) {
		this.articleReplies = articleReplies;
	}

	/*@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "article")
	public Set<AritcleVisitLog> getAritcleVisitLogs() {
		return this.aritcleVisitLogs;
	}

	public void setAritcleVisitLogs(Set<AritcleVisitLog> aritcleVisitLogs) {
		this.aritcleVisitLogs = aritcleVisitLogs;
	}*/

}